package com.lvyq.myplayer.adapter.singer

import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.lvyq.myplayer.model.singer.SingerAlbumData
import com.lvyq.myplayer.widget.singer.SingerAlbumView

/**
 * 文件描述：SingerSongAdapter
 * 作者：lvyq
 * 创建时间：2025-04-25
 * 修改时间：2025-04-25
 */
class SingerAlbumAdapter(var context: Context?,
                         private val itemClickListener: OnItemClickListener
): RecyclerView.Adapter<SingerAlbumAdapter.SingerAlbumViewHolder>() {
    lateinit var song:TextView
    lateinit var singer:TextView


    //数据定义
    var list = ArrayList<SingerAlbumData>()


    interface OnItemClickListener {
        fun onItemClick(position: Int, data: SingerAlbumData)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SingerAlbumViewHolder {
            //普通条目
            return SingerAlbumViewHolder(SingerAlbumView(parent.context))

    }


    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: SingerAlbumViewHolder, position: Int) {

            val data =list[position]
            val item = holder.itemView as SingerAlbumView
            item.setData(data)
            item.setOnClickListener{
                itemClickListener.onItemClick(position,data)
        }

    }

    // 初始化
    fun initData(lst: ArrayList<SingerAlbumData>) {
        this.list=lst
        notifyDataSetChanged()
    }


    inner class SingerAlbumViewHolder(view: View) : RecyclerView.ViewHolder(view) {

    }

}


